package com.zjbti.commonview;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class RadioButtonActivity extends AppCompatActivity {
    private RadioGroup radioGroup2;
    private TextView sex;
    private RadioButton woman;
    private RadioButton man;
    private TextView result;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_radio_button);
        radioGroup2 = (RadioGroup) findViewById(R.id.radioGroup2);
        sex = (TextView) findViewById(R.id.sex);
        woman = (RadioButton) findViewById(R.id.man);
        man = (RadioButton) findViewById(R.id.woman);
        result = (TextView) findViewById(R.id.result);
    radioGroup2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if(checkedId==R.id.woman){
                result.setText("你的性别是：女");
            }else{
                result.setText("你的性别是：男");
            }
        }
    });
    }
}